#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read() {
	register int s=0,f=1;
	register char ch=getchar();
	while(!isdigit(ch)) { if(ch=='-') f=-f; ch=getchar(); }
	while(isdigit(ch)) { s=(s<<1)+(s<<3)+(ch^48); ch=getchar(); }
	return s*f;
}
const int N=100005;
int n,Mn_1[N],Mn_2[N],ans=1e15;
struct node { 
    int a,b; 
    bool operator < (const node&t) const {
	    return b < t.b;
	}
} f[N];
signed main() {
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++) f[i].a=read(),f[i].b=read();
	sort(f+1,f+n+1);

	Mn_1[n-1] = min(f[n].a+f[n].b,f[n-1].a+f[n-1].b);
	Mn_2[n-1] = max(f[n].a+f[n].b,f[n-1].a+f[n-1].b);
	for(int i=n-2;i>=1;i--) {
		Mn_1[i] = Mn_1[i+1], Mn_2[i] = Mn_2[i+1];
		if(f[i].a+f[i].b < Mn_1[i]) {
			Mn_2[i] = Mn_1[i]; 
			Mn_1[i] = f[i].a+f[i].b;
		} else if(f[i].a+f[i].b < Mn_2[i]) {
			Mn_2[i] = f[i].a+f[i].b;
		}
	}
	for(int i=1;i<=n-2;i++) {
		ans = min(ans,f[i].a+Mn_1[i+1]+Mn_2[i+1]);
	}
	cout << ans;
	return 0;
}
